'use strict';
var csrfToken = $("meta[name='_csrf']").attr("content"),
    csrfHeader = $("meta[name='_csrf_header']").attr("content");
$(document).ajaxSend(function(c, b, a) {
    csrfToken && csrfHeader && b.setRequestHeader(csrfHeader, csrfToken)
});
jQuery.validator.setDefaults({
    errorPlacement: function(c, b) {
        var a = b.siblings("div.ck");
        a.length ? a.after(c.addClass("invalid-feedback")) : (a = b.closest(".input-btn--inline"), a.length ? a.after(c.addClass("invalid-feedback")) : b.after(c.addClass("invalid-feedback")))
    }
});
$("form[data-subscribe]").each(function() {
    $(this).validate({
        rules: {
            email: {
                required: !0,
                maxlength: 50
            }
        },
        submitHandler: function(c) {
            var b = Ladda.create(c.querySelector("button[type=submit]"));
            b.start();
            (new TencentCaptcha(captchaCodeId, function(a) {
                0 == a.ret ? $.ajax({
                    type: "POST",
                    url: contextPath + "/subscribe",
                    data: $(c).serialize() + "&" + $.param({
                        "c-tk": a.ticket,
                        "c-rs": a.randstr
                    }),
                    dataType: "json",
                    success: function(d) {
                        d.success ? Swal.fire({
                            title: "订阅成功",
                            text: "感谢您订阅我们的资讯",
                            type: "success"
                        }) : Swal.fire({
                            title: "订阅失败",
                            text: d.message,
                            type: "error"
                        })
                    },
                    complete: function() {
                        b.stop()
                    }
                }) : b.stop()
            })).show()
        }
    })
});